#include "enparseosc.h"
#include <QDebug>

EnParseOSC::EnParseOSC( OSCthulhuClient *client, EnModule *m )
{
    this->oscClient = client;
    this->module = m;

    // Local slots/signals
    QObject::connect( module, SIGNAL( bodyLocallyAdded( EnBody* ) ), this, SLOT( sendBody( EnBody* ) ) );
    QObject::connect( module, SIGNAL( bodyLocallyRemoved( QString ) ), this, SLOT( removeBody( QString ) ) );

    // OSCthulhu slots/signals
    QObject::connect( oscClient, SIGNAL( syncObjectAdded( QString ) ), this, SLOT( addObject( QString ) ) );
    QObject::connect( oscClient, SIGNAL( syncObjectRemoved( QString ) ), this, SLOT( removeObject( QString ) ) );
    QObject::connect( oscClient, SIGNAL( syncArgChanged( QString, int ) ), this, SLOT( parseArgument( QString, int ) ) );
}

void EnParseOSC::sendBody( EnBody *body )
{
    // Connect the body with our OSC parser to listen for changes
    QObject::connect( body, SIGNAL( posChanged( QString, QPointF ) ), this, SLOT( setPoint( QString, QPointF ) ) );
    QObject::connect( body, SIGNAL( colorChanged( QString, QColor ) ), this, SLOT( setColor( QString, QColor ) ) );

    // recast so we can find our coordinates and color
    QGraphicsEllipseItem* p = qgraphicsitem_cast<QGraphicsEllipseItem*>( body->getGraphicsItem() );
    qDebug() << body->getMapKey();
}

void EnParseOSC::addObject( QString msg )
{

}

void EnParseOSC::removeObject( QString msg )
{

}


void EnParseOSC::parseArgument( QString msg, int newValue )
{

}


void EnParseOSC::setPoint( QString bodyMapKey, const QPointF &point )
{
    //qDebug() << bodyMapKey;
}

void EnParseOSC::setColor( QString bodyMapKey, const QColor &color )
{
    //qDebug() << color;
}

void EnParseOSC::removeBody( QString bodyMapKey )
{

}
